package com.cskaoyan.market.controller;

import com.cskaoyan.market.db.domain.MarketStorage;
import com.cskaoyan.market.service.WxStorageService;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author cx
 * @date 2023/4/2 21:51
 * @Version 1.0
 */
@MultipartConfig
@RestController
@RequestMapping("wx/storage")
public class WxStorageController {

    @Autowired
    WxStorageService wxStorageService;

    @PostMapping("upload")
    public Object upload(@RequestParam("file") MultipartFile file, HttpServletRequest req) throws ServletException, IOException {
        if(file.getContentType().equals("image/png")){
            MarketStorage marketStorage = wxStorageService.update(file, req);
            //Part file = req.getPart("file");
            return ResponseUtil.ok(marketStorage);
        }else{
            return ResponseUtil.badArgumentValue();
        }

    }
}
